<script language="javascript" src="<?php echo JQUERYUI ?>jquery.ui.mouse.min.js"></script>
<script language="javascript" src="<?php echo JQUERYUI ?>jquery.ui.draggable.min.js"></script>
<script language="javascript" src="<?php echo JQUERYUI ?>jquery.ui.position.min.js"></script>
<script language="javascript" src="<?php echo JQUERYUI ?>jquery.ui.resizable.min.js"></script>
<script language="javascript" src="<?php echo JQUERYUI ?>jquery.ui.dialog.min.js"></script>
<script>
    $(document).ready(function() {
		$( ".date" ).datepicker();
		$( ".date" ).datepicker( "option", "dateFormat", "dd-mm-yy");
		
		$( '#jenis_bbm' ).change(function(){
			pilihan=$( '#jenis_bbm' ).val();
			if(pilihan=='cash'){
				$( '.cash' ).show();
				$( '.voucher' ).hide();
			}else{
				$( '.cash' ).hide();
				$( '.voucher' ).show();
			}
		});
        //setoran
        
		$("#penjualan_kotor").change(function(){
			$("#total_penjualan_bersih")
			.attr("value",($("#penjualan_kotor").attr("value")-
				$("#total_discount").attr("value")-$("#total_void").attr("value")-$("#fee_agen").attr("value")));
			$("#total_setoran")
			.attr("value",($("#total_penjualan_bersih").attr("value")-$("#total_biaya_langsung").attr("value")));
		});
		$("#total_discount").change(function(){
			$("#total_penjualan_bersih")
			.attr("value",($("#penjualan_kotor").attr("value")-
				$("#total_discount").attr("value")-$("#total_void").attr("value")-$("#fee_agen").attr("value")));
			$("#total_setoran")
			.attr("value",($("#total_penjualan_bersih").attr("value")-$("#total_biaya_langsung").attr("value")));
		});
		$("#total_void").change(function(){
			$("#total_penjualan_bersih")
			.attr("value",($("#penjualan_kotor").attr("value")-
				$("#total_discount").attr("value")-$("#total_void").attr("value")-$("#fee_agen").attr("value")));
			$("#total_setoran")
			.attr("value",($("#total_penjualan_bersih").attr("value")-$("#total_biaya_langsung").attr("value")));
		});
		$("#fee_agen").change(function(){
			$("#total_penjualan_bersih")
			.attr("value",($("#penjualan_kotor").attr("value")-
				$("#total_discount").attr("value")-$("#total_void").attr("value")-$("#fee_agen").attr("value")));
			$("#total_setoran")
			.attr("value",($("#total_penjualan_bersih").attr("value")-$("#total_biaya_langsung").attr("value")));
		});
		// biaya
		$("#fee_driver").change(function(){
			$("#total_biaya_langsung")
			.attr("value",(parseInt($("#fee_driver").val())+
				parseInt($("#perpal").val())+parseInt($("#bbm_cash").val())+parseInt($("#parkirtol").val())+parseInt($("#ferry_penyebrangan").val())+
				parseInt($("#makan_penumpang").val())+
				parseInt($("#snack_penumpang").val())+parseInt($("#koordinasi_lapangan").val())));
			$("#total_setoran")
			.attr("value",(parseInt($("#total_penjualan_bersih").attr("value"))-parseInt($("#total_biaya_langsung").attr("value"))));
		});
		$("#perpal").change(function(){
			$("#total_biaya_langsung")
			.attr("value",(parseInt($("#fee_driver").val())+
				parseInt($("#perpal").val())+parseInt($("#bbm_cash").val())+parseInt($("#parkirtol").val())+parseInt($("#ferry_penyebrangan").val())+
				parseInt($("#makan_penumpang").val())+
				parseInt($("#snack_penumpang").val())+parseInt($("#koordinasi_lapangan").val())));
			$("#total_setoran")
			.attr("value",(parseInt($("#total_penjualan_bersih").attr("value"))-parseInt($("#total_biaya_langsung").attr("value"))));
		});
		$("#bbm_cash").change(function(){
			$("#total_biaya_langsung")
			.attr("value",(parseInt($("#fee_driver").val())+
				parseInt($("#perpal").val())+parseInt($("#bbm_cash").val())+parseInt($("#parkirtol").val())+parseInt($("#ferry_penyebrangan").val())+
				parseInt($("#makan_penumpang").val())+
				parseInt($("#snack_penumpang").val())+parseInt($("#koordinasi_lapangan").val())));
			$("#total_setoran")
			.attr("value",(parseInt($("#total_penjualan_bersih").attr("value"))-parseInt($("#total_biaya_langsung").attr("value"))));
		});
		$("#parkirtol").change(function(){
			$("#total_biaya_langsung")
			.attr("value",(parseInt($("#fee_driver").val())+
				parseInt($("#perpal").val())+parseInt($("#bbm_cash").val())+parseInt($("#parkirtol").val())+parseInt($("#ferry_penyebrangan").val())+
				parseInt($("#makan_penumpang").val())+
				parseInt($("#snack_penumpang").val())+parseInt($("#koordinasi_lapangan").val())));
			$("#total_setoran")
			.attr("value",(parseInt($("#total_penjualan_bersih").attr("value"))-parseInt($("#total_biaya_langsung").attr("value"))));
		});
		$("#ferry_penyebrangan").change(function(){
			$("#total_biaya_langsung")
			.attr("value",(parseInt($("#fee_driver").val())+
				parseInt($("#perpal").val())+parseInt($("#bbm_cash").val())+parseInt($("#parkirtol").val())+parseInt($("#ferry_penyebrangan").val())+
				parseInt($("#makan_penumpang").val())+
				parseInt($("#snack_penumpang").val())+parseInt($("#koordinasi_lapangan").val())));
			$("#total_setoran")
			.attr("value",(parseInt($("#total_penjualan_bersih").attr("value"))-parseInt($("#total_biaya_langsung").attr("value"))));
		});
		$("#makan_penumpang").change(function(){
			$("#total_biaya_langsung")
			.attr("value",(parseInt($("#fee_driver").val())+
				parseInt($("#perpal").val())+parseInt($("#bbm_cash").val())+parseInt($("#parkirtol").val())+parseInt($("#ferry_penyebrangan").val())+
				parseInt($("#makan_penumpang").val())+
				parseInt($("#snack_penumpang").val())+parseInt($("#koordinasi_lapangan").val())));
			$("#total_setoran")
			.attr("value",(parseInt($("#total_penjualan_bersih").attr("value"))-parseInt($("#total_biaya_langsung").attr("value"))));
		});
		$("#snack_penumpang").change(function(){
			$("#total_biaya_langsung")
			.attr("value",(parseInt($("#fee_driver").val())+
				parseInt($("#perpal").val())+parseInt($("#bbm_cash").val())+parseInt($("#parkirtol").val())+parseInt($("#ferry_penyebrangan").val())+
				parseInt($("#makan_penumpang").val())+
				parseInt($("#snack_penumpang").val())+parseInt($("#koordinasi_lapangan").val())));
			$("#total_setoran")
			.attr("value",(parseInt($("#total_penjualan_bersih").attr("value"))-parseInt($("#total_biaya_langsung").attr("value"))));
		});
		$("#koordinasi_lapangan").change(function(){
			$("#total_biaya_langsung")
			.attr("value",(parseInt($("#fee_driver").val())+
				parseInt($("#perpal").val())+parseInt($("#bbm_cash").val())+parseInt($("#parkirtol").val())+parseInt($("#ferry_penyebrangan").val())+
				parseInt($("#makan_penumpang").val())+
				parseInt($("#snack_penumpang").val())+parseInt($("#koordinasi_lapangan").val())));
			$("#total_setoran")
			.attr("value",(parseInt($("#total_penjualan_bersih").attr("value"))-parseInt($("#total_biaya_langsung").attr("value"))));
		});

	} );
</script>
<form method="post" action="<?php echo RESER ?>process_setoran">
	<table align="center" width="700">
		<tr>
			<td width="180">
				Nomor SPJ :
			</td>
			<td>
				<input type="text" name="NoSPJ" value="<?php echo $reservasi['NoSPJ'] ?>" readonly size="30"/>
			</td>
		</tr>
		<tr>
			<td>
				NOPOL :
			</td>
			<td>
				<input type="text" name="NoPol" readonly value="<?php echo $reservasi['NoPol'] ?>"/>
			</td>
		</tr>
		<tr>
			<td>
				Nama Kasir :
			</td>
			<td>
				<input type="text" name="nama_kasir" readonly value="<?php echo $this->session->userdata('nama') ?>"/>
			</td>
		</tr>
        <tr>
			<td>
				Nama Driver :
			</td>
			<td>
				<input type="text" name="driver" readonly value="<?php echo $reservasi['Driver'] ?>"/>
				<input type="hidden" name="cabang_keberangkatan" readonly value="<?php echo $reservasi['KodeCabang'] ?>"/>
				<input type="hidden" name="tglspj" readonly value="<?php echo $this->date_func->change_format_date($reservasi['TGLSPJ'], 'M d Y g:iA', 'm/d/Y') ?>" size="30"/>
			</td>
		</tr>
        <tr>
			<td>
				Rute :
			</td>
			<td>
				<input type="text" name="asal" readonly value="<?php echo $reservasi['Asal'] ?>"/> - 
				<input type="text" name="tujuan" readonly value="<?php echo $reservasi['Tujuan'] ?>"/>
			</td>
		</tr>
        <tr>
			<td>
				Tanggal Pembayaran :
			</td>
			<td>
				<input class="date" type="text" name="tanggal" value="<?php echo date("m/d/Y"); //$this->date_func->change_format_date(date(), 'M d Y g:iA', 'm/d/Y')   ?>"/>
			</td>
		</tr>
        <tr>
			<td>
				Jumlah Seat :
			</td>
			<td>
				<input type="text" name="total_kapasitas" readonly value="<?php echo $jumlah_seat['JumlahKursi'] ?>"/>
			</td>
		</tr>
        <tr>
			<td>
				Jumlah Penumpang :
			</td>
			<td>
				<input type="text" name="total_penumpang" readonly value="<?php echo $jumlah_penumpang['PesanKursi'] ?>"/>
			</td>
		</tr>
		<tr>
			<td>
				Void Tiket :
			</td>
			<td>
				<input type="text" id="void_tiket" name="tiket_void" value="0"/>
			</td>
		</tr>
        <tr>
            <td colspan="2">
				PENJUALAN
			</td>
		</tr>
        <tr>
			<td>
				Penjualan Kotor :
			</td>
			<td>
				<input type="text" id="penjualan_kotor" name="penjualan_kotor" value="<?php echo $subtotal['SubTotal'] ?>"/>
			</td>
		</tr>
        <tr>
			<td>
				Potongan/ Discount :
			</td>
			<td>
				<input type="text" id="total_discount" name="total_discount" value="<?php echo $discount['Discount'] ?>"/>
			</td>
		</tr>
        <tr>
			<td>
				Void Penjualan :
			</td>
			<td>
				<input type="text" id="total_void" name="total_void" value="0"/>
			</td>
		</tr>
        <tr>
			<td>
				Fee Agen :
			</td>
			<td>
				<input type="text" id="fee_agen" name="fee_agen" value="0"/>
			</td>
		</tr>
        <tr>
			<td>
				Total Penjualan Bersih :
			</td>
			<td>
				<input type="text" readonly id="total_penjualan_bersih" name="total_penjualan_bersih" value="<?php echo ($subtotal['SubTotal'] - $discount['Discount']) ?>"/>
			</td>
		</tr>
		<tr>
            <td colspan="2">
				BIAYA AWAL
			</td>
		</tr>
		<?php
		for ($i = 0; $i < count($biaya_awal); $i++) {
			if ($biaya_awal[$i]['jumlah'] > 0) {
				?>
				<tr>
					<td>
		<?php echo $biaya_awal[$i]['nama_coa'] ?> :
					</td>
					<td>
						<input type="text" id="<?php echo $biaya_awal[$i]['nama_coa'] ?>" readonly name="<?php echo $biaya_awal[$i]['nama_coa'] ?>" 
							   value="<?php echo $biaya_awal[$i]['jumlah'] ?>"/>
					</td>
				</tr>
	<?php }
} ?>
		<td colspan="2">
			BIAYA
		</td>
		</tr>
        <tr>
			<td>
				Fee Driver :
			</td>
			<td>
<?php echo (($fee_driver*$jumlah_penumpang['PesanKursi']) + (($chargeA['ChargeA'] + $chargeB['ChargeB']) * $charge_supir/100)) ?>
				<input type="hidden" id="fee_driver" name="fee_driver" value="<?php echo (($fee_driver*$jumlah_penumpang['PesanKursi']) + (($chargeA['ChargeA'] + $chargeB['ChargeB']) * $charge_supir/100)) ?>"/>
				<input type="hidden" name="chargeA" value="<?php echo $chargeA['ChargeA']; ?>" />
				<input type="hidden" name="chargeB" value="<?php echo $chargeB['ChargeB']; ?>" />
			</td>
		</tr>
        <tr>
			<td>
				PERPAL :
			</td>
			<td>
				<input type="text" id="perpal" name="perpal" value="<?php 
//                                if (count($biaya_awal)>0)
//                                {
//                                    echo $biaya_awal[1]['jumlah'];
//                                }
//                                else 
                                    echo 0;
                                ?>"/>
			</td>
		</tr>
        <tr>
			<td>
				Pilihan BBM :
			</td>
			<td>
				<select id="jenis_bbm" name="jenis_bbm"">
                                        <option >cash</option>
					<option>voucher</option>
				</select>
			</td>
		</tr>
		<tr class="cash">
			<td>
				Jumlah :
			</td>
			<td>
				<input type="text" id="bbm_cash" name="bbm_cash" value="<?php 
//                                if (count($biaya_awal)>0)
//                                {
//                                    echo $biaya_awal[2]['jumlah'];
//                                }else 
                                    echo 0;
                                ?>"/>
			</td>
		</tr>
		<tr class="voucher" style="display:none">
			<td>
				SPBU
			</td>
			<td>
				<?php
                                $id_spbu = '';
                                if(isset($spbu_voucher['idspbu']))
                                    $id_spbu = $spbu_voucher['idspbu'];
				for ($i = 0; $i < count($spbu); $i++) {
					$opt[$spbu[$i]['id']] = $spbu[$i]['nama'];
				}
				echo form_dropdown('idspbu', $opt,$id_spbu);
				?>
			</td>
		</tr>
		<tr class="voucher" style="display:none">
			<td>
				Kode Voucher :
			</td>
			<td>
				<?php
                                $kode_voucher = '';
                                if(isset($spbu_voucher['kode_voucher'])) 
                                    $kode_voucher = $spbu_voucher['kode_voucher'];
				echo '<input type="text" name="kode_voucher" value="'.$kode_voucher.'"/>';
				?>
			</td>
		</tr>
		<tr class="voucher" style="display:none">
			<td>
				Jenis BBM :
			</td>
			<td>
                            <?php
                            $jenis_bbm = '';
                            if(isset($spbu_voucher['jenis_bbm']))
                                $jenis_bbm = $spbu_voucher['jenis_bbm'];
                            ?>
				<select name="tipe_bbm">
                                    <option <?php if($jenis_bbm=='solar') echo 'selected'; ?>>solar</option>
					<option <?php if($jenis_bbm=='premium') echo 'selected'; ?>>premium</option>
				</select>
			</td>
		</tr>
		<tr class="voucher" style="display:none">
			<td>
				Jumlah Liter:
			</td>
			<td>
                            <?php 
                            $jumlah_liter = '';
                            if(isset($spbu_voucher['jumlah_liter']))
                                $jumlah_liter = $spbu_voucher['jumlah_liter'];
                            ?>
                            <input type="text" name="jumlah_liter" value="<?php echo $jumlah_liter ?>"/>
			</td>
		</tr>
		<tr class="voucher" style="display:none">
			<td>
				Jumlah Biaya :
			</td>
			<td>
                            <?php 
                            $jumlah_uang = '';
                            if(isset($spbu_voucher['jumlah_uang']))
                                $jumlah_uang = $spbu_voucher['jumlah_uang'];
                            ?>
                            <input type="text" name="jumlah_uang" value="<?php echo $jumlah_uang ?>"/>
			</td>
		</tr>
        <tr>
			<td>
				Parkir & Tol :
			</td>
			<td>
				<input type="text" id="parkirtol" name="parkirtol" value="<?php 
//                                if (count($biaya_awal)>0)
//                                {
//                                    echo $biaya_awal[3]['jumlah'];
//                                }else
                                    echo 0;
                                ?>"/>
			</td>
		</tr>
        <tr>
			<td>
				Ferry Penyebrangan :
			</td>
			<td>
				<input type="text" id="ferry_penyebrangan" name="ferry_penyebrangan" value="<?php 
//                                if (count($biaya_awal)>0)
//                                {
//                                    echo $biaya_awal[4]['jumlah'];
//                                }else 
                                    echo 0;
                                ?>"/>
			</td>
		</tr>
        <tr>
			<td>
				Makan Penumpang :
			</td>
			<td>
				<input type="text" id="makan_penumpang" name="makan_penumpang" value="<?php 
//                                if (count($biaya_awal)>0)
//                                {
//                                    echo $biaya_awal[5]['jumlah'];
//                                }else 
                                    echo 0;
                                ?>"/>
			</td>
		</tr>
        <tr>
			<td>
				Snack Penumpang :
			</td>
			<td>
				<input type="text" id="snack_penumpang" name="snack_penumpang" value="<?php 
//                                if (count($biaya_awal)>0)
//                                {
//                                    echo $biaya_awal[6]['jumlah'];
//                                }else 
                                    echo 0;
                                ?>"/>
			</td>
		</tr>
        <tr>
			<td>
				Koordinasi Lapangan :
			</td>
			<td>
				<input type="text" id="koordinasi_lapangan" name="koordinasi_lapangan" value="<?php 
//                                if (count($biaya_awal)>0)
//                                {
//                                    echo $biaya_awal[7]['jumlah'];
//                                }else 
                                    echo 0;
                                ?>"/>
			</td>
		</tr>
		<tr>
			<td>
				TOTAL BIAYA :
			</td>
			<td>
				<input type="text" readonly id="total_biaya_langsung" name="total_biaya_langsung" value="<?php echo (($fee_driver*$jumlah_penumpang['PesanKursi']) + (($chargeA['ChargeA'] + $chargeB['ChargeB']) * $charge_supir/100)) ?>"/>
			</td>
		</tr>
		<tr>
			<td>
				TOTAL Setor :
			</td>
			<td>
				<input type="text" readonly id="total_setoran" name="total_setoran" value="<?php echo ($subtotal['SubTotal'] - $discount['Discount'] - (($fee_driver*$jumlah_penumpang['PesanKursi'])+ (($chargeA['ChargeA'] + $chargeB['ChargeB']) * $charge_supir/100))) ?>"/>
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center">
				<input type="submit" value="Buat"/>
			</td>
		</tr>
	</table>
</form>